import 'package:easy_rich_text/easy_rich_text.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/app_colors.dart';
import 'package:tiktokadult/config/config.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:tiktokadult/routers/jump_router.dart';
import 'package:tiktokadult/tools_base/widget/common_dialog.dart';

import '../../hj_utils/utils.dart';

class SysDomainErrorAlert extends StatelessWidget {
  static Future show({Function? callback}) {
    return Get.dialog(
      SysDomainErrorAlert(callback: callback),
      barrierDismissible: false,
    );
  }

  final Function? callback;

  const SysDomainErrorAlert({Key? key, this.callback}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CommonDialog(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            '系统提示',
            style: TextStyle(
              color: Colors.white.withOpacity(.9),
              fontSize: 20,
              fontWeight: FontWeight.w500,
            ),
          ),
          12.sizeBoxH,
          0.5.line,
          12.sizeBoxH,
          Row(
            children: [
              Text(
                "APP线路检测失败",
                style: TextStyle(
                  color: Color(0xffF52C56),
                  fontSize: 12,
                ),
              ),
            ],
          ),
          12.sizeBoxH,
          Container(
            alignment: Alignment.centerLeft,
            child: const Text(
              "解决方案：",
              style: TextStyle(color: Color(0xff656565), fontSize: 12, fontWeight: FontWeight.w500),
            ),
          ),
          12.sizeBoxH,
          EasyRichText(
            '''1.请检测您的网络是否正常，手机是否开了VPN或10分钟后再尝试访问。 
2.前往官网地址 https://xv9.fm/下载最新版。
官方备用：XV9.ME 
3.前往Telegram${Config.APPNAME}官方交流群
            ''',
            defaultStyle: TextStyle(fontSize: 12, color: Color(0xff656565), height: 1.8),
            patternList: [
              EasyRichTextPattern(
                targetString: 'https://xv9.fm/',
                style: TextStyle(color: AppColors.primaryHighColor),
                recognizer: TapGestureRecognizer()
                  ..onTapDown = (details) {
                    launchUrlToWeb('https://xv9.fm/');
                  },
              ),
            ],
          ),
          18.sizeBoxH,
          SizedBox(
            height: 38,
            child: Row(
              children: [
                GestureDetector(
                  onTap: () async {
                    Navigator.pop(context);
                    callback?.call();
                  },
                  child: Container(
                    width: 96,
                    height: 42,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(3),
                      color: Colors.white.withOpacity(.1),
                    ),
                    child: Text(
                      "切换路线",
                      style: TextStyle(
                        color: Color(0xff989898),
                        fontSize: 14,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                ),
                12.sizeBoxW,
                Expanded(
                  child: GestureDetector(
                    onTap: () {
                      launchUrlMethod('https://t.me/Xzhangf');
                    },
                    child: Container(
                      height: 42,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(3),
                        color: AppColors.actionRed,
                      ),
                      child: const Text(
                        "前往群聊",
                        style: TextStyle(
                          color: Colors.white,
                          fontSize: 16,
                          fontWeight: FontWeight.w500,
                        ),
                      ),
                    ),
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
